package com.qnbc.mystery.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.qnbc.mystery.core.annotation.Log;
import com.qnbc.mystery.core.controller.BaseController;
import com.qnbc.mystery.core.domain.AjaxResult;
import com.qnbc.mystery.core.enums.BusinessType;
import com.qnbc.mystery.core.page.TableDataInfo;
import com.qnbc.mystery.core.utils.poi.ExcelUtil;
import com.qnbc.mystery.pojo.domain.BigType;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qnbc.mystery.service.IBigTypeService;

/**
 * 商品大类
 *
 * @author guzj
 * @date 2024-01-24
 */
@Api("商品大分类管理")
@RestController
@RequestMapping("/bigtype")
public class BigTypeController extends BaseController {
    @Autowired
    private IBigTypeService bigTypeService;

    /**
     * 查询大类展示列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BigType bigType) {
        startPage();
        List<BigType> list = bigTypeService.selectBigTypeList(bigType);
        return getDataTable(list);
    }

    /**
     * 导出大类展示列表
     */
    @Log(title = "大类展示", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BigType bigType) {
        List<BigType> list = bigTypeService.selectBigTypeList(bigType);
        ExcelUtil<BigType> util = new ExcelUtil<BigType>(BigType.class);
        util.exportExcel(response, list, "大类展示数据");
    }

    /**
     * 获取大类展示详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bigTypeService.selectBigTypeById(id));
    }

    /**
     * 新增大类展示
     */
    @Log(title = "大类展示", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BigType bigType) {
        return toAjax(bigTypeService.insertBigType(bigType));
    }

    /**
     * 修改大类展示
     */
    @Log(title = "大类展示", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BigType bigType) {
        return toAjax(bigTypeService.updateBigType(bigType));
    }

    /**
     * 删除大类展示
     */
    @Log(title = "大类展示", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bigTypeService.deleteBigTypeByIds(ids));
    }
}
